import { defineStore } from 'pinia'
import request from '@/utils/request'
import {
  BannerItem,
  ApiRes,
  GoodsItem,
  HotGoods,
  Brand,
  HomeProduct,
  HomeSpecial
} from '@/types/data'

const useHomeStore = defineStore('home', {
  state() {
    return {
      bannarList: [] as BannerItem[],
      NewGoodsList: [] as GoodsItem[],
      hotGoodList: [] as HotGoods[],
      brandList: [] as Brand[],
      ProductList: [] as HomeProduct[],
      SpecialList: [] as HomeSpecial[]
    }
  },
  actions: {
    async getBannarList() {
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      this.bannarList = res.data.result
    },
    //新鲜好物数据
    async getNewGoodsList() {
      const res = await request.get<ApiRes<GoodsItem[]>>('/home/new')
      this.NewGoodsList = res.data.result
    },
    //人气推荐数据
    async getHotList() {
      const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
      this.hotGoodList = res.data.result
    },
    //热门品牌
    async getBrandList() {
      const res = await request.get<ApiRes<Brand[]>>('/home/brand')
      this.brandList = res.data.result
    },
    // 商品块区
    async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      this.ProductList = res.data.result
    },
    //最新专题
    async getSpecialList() {
      const res = await request.get<ApiRes<HomeSpecial[]>>('/home/special')
      this.SpecialList = res.data.result
    }
  },
  getters: {}
})

export default useHomeStore
